package com.ghy.nba.controllers;

import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.xml.transform.Result;
import java.io.PrintWriter;
import java.security.Principal;
import java.util.Map;


@Controller
public class LoginControllers {
    @RequestMapping("/login")

    public String login(Model model) {
        Authentication auth= SecurityContextHolder.getContext().getAuthentication();
        //判断用户是否已登录：1：如果未登录，则跳转到登录界面。2：如果登录，不作跳转
        if (!(auth instanceof AnonymousAuthenticationToken)){
            String currUsername= auth.getName();  //获取登录信息
            model.addAttribute("currUsername",currUsername); //传到试图层
            return "main/home";
        }else {

            return "login/login";
        }
    }

    @RequestMapping("/logout")
    public String logout() {

        return "";
    }
}